package LeetCode.month02.day43;

import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

public class No128 {
    public int longestConsecutive(int[] nums) {
        Set<Integer> set = new TreeSet<>();
        int n = nums.length;
        for (int i = 0; i < n; i++) {
            set.add(nums[i]);
        }
        int res = 0;
        for (Integer i : set) {
            if(set.contains(i-1)) continue;
            int y = i+1;
            while(set.contains(y)){
                y=y+1;
            }
            res = Math.max(y-i,res);
        }
        return res;
    }
}
